package oop.ex1.orders;

import java.io.*;
import java.util.Comparator;

/**This class handles the Order processes in this program. 
 * @author miron_6 && dawn16889.
 *
 */
public class OrderType{
	
	public OrderType(){}
	/**This method uses order's enums to decide which order to use in every TreeSet of files.
	 * @param readLine - String converted into Order object. 
	 * @return the correct Order object according to String and enum.
	 */
	public static Comparator<File> treeOrder(String readLine) throws OrderNameException  {
		try{
			eOrder ord = eOrder.valueOf(readLine);
			switch (ord){
			case abs:
				return new Order.absSort();
			case file:
				return new Order.fileSort();
			case mod:
				return new Order.modSort();
			case size:
				return new Order.sizeSort();
			default:
				return null;
			}
		}
		catch (IllegalArgumentException exc){
			throw new OrderNameException("ERROR");
		}
		
	}
}
